<?php

namespace app\http\middleware;

use app\common\Base;

class Check extends Base
{
    public function handle($request, \Closure $next,$type)
    {
        $request->cacheInfo = json_decode(app('mycache')->get($_SERVER['HTTP_TOKEN']),true);
        //判断是否登录
        if (empty($request->cacheInfo)){
            return responseJson(Base::NOT_LOGGED_IN,'尚未登录，跳转到登录页面1');
        }
        //判断用户的权限
        if ($type == 'Buyer'){
            if ($request->cacheInfo['type'] != 'Buyer'){
                return responseJson(Base::NOT_LOGGED_IN,'尚未登录，请先登录后再访问2');
            }
        }
        //判断商家的权限
        if ($type == 'seller'){
            if ($request->cacheInfo['type'] != 'seller'){
                return responseJson(Base::NOT_LOGGED_IN,'尚未登录，请先登录后再访问3');
            }
        }
        return $next($request);
    }
}
